package com.ruoyi.web.controller.installation;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.WaterMeterinstallinfo;
import com.ruoyi.system.service.IWaterMeterinstallinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 表具安装Controller
 *
 * @author ruoyi
 * @date 2025-09-16
 */
@RestController
@RequestMapping("/installation/installInfo")
public class WaterMeterinstallinfoController extends BaseController
{
    @Autowired
    private IWaterMeterinstallinfoService waterMeterinstallinfoService;

    /**
     * 查询表具安装列表
     */
    @PreAuthorize("@ss.hasPermi('installation:installInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(WaterMeterinstallinfo waterMeterinstallinfo)
    {
        startPage();
        List<WaterMeterinstallinfo> list = waterMeterinstallinfoService.selectWaterMeterinstallinfoList(waterMeterinstallinfo);
        return getDataTable(list);
    }

    /**
     * 导出表具安装列表
     */
    @PreAuthorize("@ss.hasPermi('installation:installInfo:export')")
    @Log(title = "表具安装", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WaterMeterinstallinfo waterMeterinstallinfo)
    {
        List<WaterMeterinstallinfo> list = waterMeterinstallinfoService.selectWaterMeterinstallinfoList(waterMeterinstallinfo);
        ExcelUtil<WaterMeterinstallinfo> util = new ExcelUtil<WaterMeterinstallinfo>(WaterMeterinstallinfo.class);
        util.exportExcel(response, list, "表具安装数据");
    }

    /**
     * 获取表具安装详细信息
     */
    @PreAuthorize("@ss.hasPermi('installation:installInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(waterMeterinstallinfoService.selectWaterMeterinstallinfoById(id));
    }

    /**
     * 新增表具安装
     */
    @PreAuthorize("@ss.hasPermi('installation:installInfo:add')")
    @Log(title = "表具安装", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WaterMeterinstallinfo waterMeterinstallinfo)
    {
        LoginUser loginUser = getLoginUser();
        waterMeterinstallinfo.setCompanyId(loginUser.getDeptId().toString());
        waterMeterinstallinfo.setInstallState("0");
        int resultNum = waterMeterinstallinfoService.insertWaterMeterinstallinfo(waterMeterinstallinfo);
        if(resultNum>0){
            return toAjax(resultNum);
        }
        return AjaxResult.warn("该工单已经创建过报装记录");
    }

    /**
     * 修改表具安装
     */
    @PreAuthorize("@ss.hasPermi('installation:installInfo:edit')")
    @Log(title = "表具安装", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WaterMeterinstallinfo waterMeterinstallinfo)
    {
        return toAjax(waterMeterinstallinfoService.updateWaterMeterinstallinfo(waterMeterinstallinfo));
    }

    /**
     * 删除表具安装
     */
    @PreAuthorize("@ss.hasPermi('installation:installInfo:remove')")
    @Log(title = "表具安装", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(waterMeterinstallinfoService.deleteWaterMeterinstallinfoByIds(ids));
    }
}
